﻿using Hangfire;
using Hangfire.MySql;
using Microsoft.Extensions.Configuration;
using System.Configuration;

namespace Net7Docker.Extensions
{
    /// <summary>
    /// Hangfire安装
    /// </summary>
    public static class HangfireSetup
    {
        public static void AddHangfire(this WebApplicationBuilder builder)
        {
            builder.Services.AddHangfire(configuration => configuration
            .SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
            .UseSimpleAssemblyNameTypeSerializer()
            .UseRecommendedSerializerSettings()
            .UseStorage(new MySqlStorage(builder.Configuration["HangfireConnectStr"], new MySqlStorageOptions()
            {
                TablesPrefix = "hangfire"
            }))
            ).AddHangfireServer(configuration =>
            {
                //不支持秒级，垃圾
                configuration.WorkerCount = 1;
                configuration.SchedulePollingInterval = TimeSpan.FromSeconds(10);
            });


        }
    }
}
